package com.example.layouttest305;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private TextView wenben;
    private EditText edit;
    private Button gettext,setimage;
    private ImageView tu;
    private ImageButton tu1;
    private RadioGroup xingbie;
    private RadioButton nan,nv;
    private CheckBox lan,zu,pai;
    private Button huoquxingbie,huoquaihao;
    private String strfun="";
    boolean flag1 = true;
    boolean flag2 = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }
    private void init(){
        wenben=(TextView)findViewById(R.id.TextView);
        edit=(EditText)findViewById(R.id.editText3);
        gettext=(Button) findViewById(R.id.button);
        setimage=(Button) findViewById(R.id.button2);
        tu=(ImageView)findViewById(R.id.imageView);
        tu1=(ImageButton) findViewById(R.id.imageButton);
        gettext.setOnClickListener(this);
        setimage.setOnClickListener(this);
        tu1.setOnClickListener(this);
        xingbie=(RadioGroup)findViewById(R.id.radio_group);
        nan=(RadioButton)findViewById(R.id.radioButton);
        nv=(RadioButton)findViewById(R.id.radioButton2);
        lan=(CheckBox)findViewById(R.id.checkBox);
        zu=(CheckBox)findViewById(R.id.checkBox2);
        pai=(CheckBox)findViewById(R.id.checkBox3);
        huoquxingbie=(Button)findViewById(R.id.button3);
        huoquaihao=(Button)findViewById(R.id.button4);
        huoquxingbie.setOnClickListener(this);
        huoquaihao.setOnClickListener(this);

        xingbie.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.radioButton:
                        wenben.setText("男");
                        break;
                    case R.id.radioButton2:
                        wenben.setText("女");
                        break;
                }
            }
        });
        lan.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    strfun+="篮球+";
                }
                else {
                    strfun=strfun.replace("篮球+","");
                }
                wenben.setText(strfun);
            }
        });
        pai.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    strfun+="排球+";
                }
                else {
                    strfun=strfun.replace("排球+","");
                }
                wenben.setText(strfun);
            }
        });
        zu.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    strfun+="足球+";
                }
                else {
                    strfun=strfun.replace("足球+","");
                }
                wenben.setText(strfun);
            }
        });
    }
    public void onClick(View view){
        switch (view.getId()){
            case R.id.button:
                String str=edit.getText().toString();
                wenben.setText(str);
                break;
            case R.id.button2:

                if (flag1){
                    wenben.setText("图片更换");
                    tu.setImageResource(R.drawable.szx);
                    flag1 = false;
                }else {
                    wenben.setText("图片更换");
                    tu.setImageResource(R.mipmap.ic_launcher);
                    flag1 =true;
                }

                break;
            case R.id.imageButton:
                if (flag2){
                    wenben.setText("图片更换");
                    tu1.setImageResource(R.drawable.szx);
                    flag2 = false;
                }else {
                    wenben.setText("图片更换");
                    tu1.setImageResource(R.mipmap.ic_launcher);
                    flag2 =true;
                }
                break;
            case R.id.button3:
                if(nan.isChecked()) wenben.setText("男");
                if(nv.isChecked()) wenben.setText("女");
                break;
            case R.id.button4:
                String msg="";
                if (lan.isChecked())  msg+="篮球+";
                if (zu.isChecked())  msg+="足球+";
                if (pai.isChecked())  msg+="排球";
                wenben.setText(msg);
                break;
        }

    }
}
